;
(function() {
	'use strict';
	angular.module('controllers.resourcesWatchData.detInfoDisplay')
		.controller('detInfoDisplayController', detInfoDisplayController);

	function detInfoDisplayController($scope, detInfoDisplayService, allInfoDisplayService, CoreService) {
		//控制查询条件拉上拉下   1为拉下  0 为拉上
		$scope.shoumun = {
			num: 1
		};
		$scope.states = detInfoDisplayService.getState();
		$scope.maintainModes = detInfoDisplayService.getMaintainMode();
		$scope.sendData = {
			stateCode: '1',
			modeCode: '1'
		};

		var params = {};
		//控制等待样式   false 为隐藏   true 为显示
		$scope._loading.show = false;
		var myEcharts = echarts.init(document.getElementById('doc'));
		var myEcharts1 = echarts.init(document.getElementById('doc1'));
		var myEcharts2 = echarts.init(document.getElementById('doc2'));
		var myEcharts3 = echarts.init(document.getElementById('doc3'));
		var myEcharts4 = echarts.init(document.getElementById('doc4'));
		var myEcharts5 = echarts.init(document.getElementById('doc5'));
		var myEcharts6 = echarts.init(document.getElementById('doc6'));
		var myEcharts7 = echarts.init(document.getElementById('doc7'));
		var myEcharts8 = echarts.init(document.getElementById('doc8'));
		var myEcharts9 = echarts.init(document.getElementById('doc9'));
		// var myEcharts10 = echarts.init(document.getElementById('doc10'));
		var myEcharts11 = echarts.init(document.getElementById('doc11'));
		//主机详细信息
		$scope.search = function() {

			if ($scope.shoumun.num === 1) {
				$scope.shoumun.num = 1;
				return;
			}
			detInfoDisplayService.queryInfo($scope.sendData, function(res) {
				if (res.state === '10000' && res.data.length >= 1) {
					$scope.items = res.data;
					$scope.shoumun.num = 0;
					$scope.flag = 'table';
				}else if(res.data.length === 0){
					$scope.flag = '';
					CoreService.dialog('查询无数据');
				}else {
					$scope.flag = '';
					CoreService.dialog('查询错误');
				}

			});
		};
		// $scope.back = function() {
		// 	$scope.flag = 'table';
		// };
		//状态
		// $scope.queryState = function(info) {
		// 	$scope.hostInfo = info;
		// 	detInfoDisplayService.queryState(params, function(res) {
		// 		$scope.runMessage = res.data[0].runStateData;
		// 		var a = allInfoDisplayService.getHostInfo(res, 'cpuData', 'cpu平均使用情况', '使用比率');
		// 		var b = allInfoDisplayService.getHostInfo(res, 'diskData', '磁盘平均使用情况', '千字节/秒');
		// 		var c = allInfoDisplayService.getHostInfo(res, 'ramData', '内存平均使用情况', '百分比(%)');
		// 		var d = allInfoDisplayService.getHostInfo(res, 'interData', '网络平均使用情况', '(k/s)');
		// 		var echartsConfig = echarts.config;

		// 		myEcharts.setOption(a);
		// 		// myEcharts.on(echartsConfig.EVENT.CLICK, cpuDown);

		// 		myEcharts1.setOption(b);
		// 		myEcharts1.on(echartsConfig.EVENT.CLICK, diskDown);

		// 		myEcharts2.setOption(c);
		// 		myEcharts2.on(echartsConfig.EVENT.CLICK, ramDown);

		// 		myEcharts3.setOption(d);
		// 		myEcharts3.on(echartsConfig.EVENT.CLICK, interDown);
		// 		$scope.flag = 'state';
		// 	});
		// };
		//状态-->cpu下钻
		// function cpuDown() {
		// 	detInfoDisplayService.queryCpuNat(params, function(res) {
		// 		var k = detInfoDisplayService.getEchartsData(res);
		// 		myEcharts10.setOption(k);
		// 		$scope.flag = 'cpuDown';
		// 	});
		// }
		//状态-->磁盘下钻
		function diskDown() {
			return;
			detInfoDisplayService.queryDiskNat(params, function(res) {
				var temp = {
					echartsPieTitle: '硬盘空间使用',
					echartsPieLegend: ['可用空间', '已用空间'],
					echartsPieSeriesData: [{
						value: res.data[0].diskUsageRate[0].size,
						name: '可用空间'
					}, {
						value: res.data[0].diskUsageRate[0].surplusSize,
						name: '已用空间'
					}]
				};
				var e = detInfoDisplayService.getEchartsPieData(res, temp);
				var f = allInfoDisplayService.getHostInfo(res, 'diskReadRate', '磁盘-读', '千字节/秒');
				var g = allInfoDisplayService.getHostInfo(res, 'diskWriteRate', '磁盘-写', '千字节/秒');
				myEcharts4.setOption(e);
				myEcharts5.setOption(f);
				myEcharts6.setOption(g);
				$scope.flag = 'diskDown';
			});
		}
		//状态-->内存下钻
		function ramDown() {
			return;
			detInfoDisplayService.queryRamNat(params, function(res) {
				var temp = {
					echartsPieTitle: '内存空间使用',
					echartsPieLegend: ['为硬件保留的内存', '正在使用', '可用'],
					echartsPieSeriesData: [{
						value: res.data[0].diskUseRam,
						name: '为硬件保留的内存'
					}, {
						value: res.data[0].usedRam,
						name: '正在使用'
					}, {
						value: res.data[0].rcdRam,
						name: '可用'
					}]
				};
				var h = detInfoDisplayService.getEchartsPieData(res, temp);
				myEcharts7.setOption(h);
				$scope.flag = 'ramDown';
			});
		}
		//状态-->内存下钻
		function interDown() {
			return;
			detInfoDisplayService.queryInterNat(params, function(res) {
				var i = allInfoDisplayService.getHostInfo(res, 'netReqRate', '网络-发送', 'k/s');
				var j = allInfoDisplayService.getHostInfo(res, 'netResRate', '网络-接收', 'k/s');
				myEcharts8.setOption(i);
				myEcharts9.setOption(j);
				$scope.flag = 'interDown';
			});
		}
		//运行状况显示
		$scope.show = function() {
			CoreService.dialog('暂无数据');
		};
		//进程
		$scope.queryProcess = function() {
			CoreService.dialog('暂无数据');
			return;
			// detInfoDisplayService.queryProcess(params, function(res) {
			// 	$scope.processData = res.data;
			// 	$scope.flag = 'process';
			// });
		};
		//资源
		$scope.queryResources = function() {
			CoreService.dialog('暂无数据');
			return;
			// detInfoDisplayService.queryResources(params, function(res) {
			// 	$scope.resources = res.data[0];
			// 	$scope.flag = 'resource';
			// });
		};
		//资源-->cpu服务下钻
		$scope.cpuServerDown = function() {
			return;
			resourceDown('cpuRate', 'cpu使用比率', '使用比率');
		};

		function resourceDown(dataModule, title, yName) {
			return;
			detInfoDisplayService.queryResources(params, function(res) {
				var l = allInfoDisplayService.getHostInfo(res, dataModule, title, yName);
				myEcharts11.setOption(l);
				$scope.flag = 'resourcesDown';
			});
		}
		//资源-->内存服务下钻
		$scope.ramServerDown = function() {
			return;
			resourceDown('ramRate', '内存', '百分比');
		};
		//资源-->磁盘服务下钻
		$scope.diskServerDown = function() {
			return;
			resourceDown('diskRate', '磁盘', '千字节/秒');
		};
		//资源-->网络服务下钻
		$scope.interServerDown = function() {
			return;
			resourceDown('interRate', '网络', 'k/s');
		};
		//组件
		$scope.queryComponent = function() {
			CoreService.dialog('暂无数据');
			return;
			// detInfoDisplayService.queryComponent(params, function(res) {
			// 	$scope.components = res.data;
			// 	$scope.flag = 'component';
			// });
		};
		//状态返回
		$scope.stateBack = function() {
			$scope.flag = 'state';
		};
		//资源返回
		$scope.resourceBack = function() {
			$scope.flag = 'resource';
		};
	}
})();